package com.stars.easyms.mq.asyn;

import com.stars.easyms.base.asynchronous.BaseBatchAsynchronousTask;
import com.stars.easyms.datasource.batch.BatchCommit;
import com.stars.easyms.base.batch.BatchResult;
import com.stars.easyms.mq.dto.MQMessageDTO;
import com.stars.easyms.mq.util.EasyMsMQPackageUtil;
import com.stars.easyms.base.util.ApplicationContextHolder;

import java.util.List;

/**
 * 异步发送mq消息，由于发送mq信息速度较慢因此采用异步的方式：先把数据批量存入数据库，然后采用线程池的方式批量发送MQ消息
 *
 * @author guoguifang
 * @date 2018-04-23 13:54
 * @since 1.0.0
 */
public class AsynUpdateMQMessage extends BaseBatchAsynchronousTask<MQMessageDTO> {

    private BatchCommit batchCommit;

    @Override
    protected BatchResult execute(List<MQMessageDTO> mqMessageDTOList) {
        return batchCommit.batchUpdate(EasyMsMQPackageUtil.getRepositoryClassName() + "." + "updateMQMessageByPrimaryKey", mqMessageDTOList);
    }

    public AsynUpdateMQMessage() {
        this.batchCommit = ApplicationContextHolder.getBean(BatchCommit.class);
    }

}
